package net.hubt.itc.data;

import java.util.ArrayList;
import java.util.List;

public class ClassLookSpin {
	
	protected List <ClassLook> m_arr_All;
	protected List <String> m_arr_Lop;
	protected List <String> m_arr_Nganh;
	protected List <String> m_arr_KhoaHoc;
	protected int sizeNganh;
	protected int sizeKhoaHoc;
	protected int sizeLop;
	protected int sizeAll;

	
	public ClassLookSpin(){
		m_arr_All = new ArrayList<ClassLook>();
		m_arr_Nganh = new ArrayList<String>();
		m_arr_KhoaHoc = new ArrayList<String>();
			
	}
	
	public List <ClassLook> getarr_All(){
		return m_arr_All;
	}
	
	public void setarr_All( List <ClassLook> arr_All){
		m_arr_All = arr_All;
	}
	
	public void addClassLook (ClassLook classLookObj ){
		if(m_arr_All == null)
			m_arr_All = new ArrayList<ClassLook>();
		m_arr_All.add(classLookObj);
	}

	public ClassLook getClassLook(int index){
		if ((m_arr_All !=null) && (m_arr_All.size()>0)){
			return m_arr_All.get(index);
		}
		return null;
	}
	public void addLop (String lop){
		m_arr_Lop.add(lop);
	}
	
	public String getLop (int index){
		if ((m_arr_Lop !=null) && (m_arr_Lop.size()>0)){
		return m_arr_Lop.get(index);
	}
	return null;
	}
	
	public void addNganh (String nganh){
		m_arr_Nganh.add(nganh);
	}
	
	public String getNganh (int index){
		if ((m_arr_Nganh !=null) && (m_arr_Nganh.size()>0)){
		return m_arr_Nganh.get(index);
		}
		return null;
	}
	
	public void addKhoaHoc (String khoahoc){
		m_arr_KhoaHoc.add(khoahoc);
	}
	
	public String getKhoaHoc (int index){
		if ((m_arr_KhoaHoc !=null) && (m_arr_KhoaHoc.size()>0)){
		return m_arr_KhoaHoc.get(index);
		}
		return null;
	}
	
	public int getsizeKhoaHoc(){
		return sizeKhoaHoc;
	}
	
	public int getsizeNganh(){
		return sizeNganh;
	}
	
	public int getsizeLop(){
		return sizeLop;
		
	}
	public int getsizeAll(){
		return sizeAll;
		
	}

	
	public void filterKhoaHoc (){
		if(m_arr_KhoaHoc!=null) m_arr_KhoaHoc.clear();
		m_arr_KhoaHoc = new ArrayList<String>();
		List<ClassLook> arr_All= new ArrayList<ClassLook>(m_arr_All.size());

		for (ClassLook clsLook: m_arr_All) {
			  arr_All.add((ClassLook)clsLook.clone());
			}
		for (int i=0;i<arr_All.size();i++){
			if(!arr_All.get(i).getCheck()){
				m_arr_KhoaHoc.add(arr_All.get(i).getKhoaHoc());
					for(int j=i+1;j<arr_All.size();j++)
						if (arr_All.get(j).getKhoaHoc().equals(arr_All.get(i).getKhoaHoc()))
							arr_All.get(j).setCheck(true);
						
			}
		}
		sizeAll = m_arr_All.size();
		sizeKhoaHoc = m_arr_KhoaHoc.size();
	}
	public void filterNganh (String khoaHoc){
		if(m_arr_Nganh!=null) m_arr_Nganh.clear();
		m_arr_Nganh = new ArrayList<String>();
		List<ClassLook> arr_All= new ArrayList<ClassLook>(m_arr_All.size());

		for (ClassLook clsLook: m_arr_All) {
			  arr_All.add((ClassLook)clsLook.clone());
			}
		for (int i=0;i<arr_All.size();i++){
			if(arr_All.get(i).getKhoaHoc().equals(khoaHoc) && (arr_All.get(i).getCheck()== false) ){
				m_arr_Nganh.add(arr_All.get(i).getNganh());
				
				for(int j=i+1;j<arr_All.size();j++)
					if (arr_All.get(j).getNganh().equals(arr_All.get(i).getNganh()))
						arr_All.get(j).setCheck(true);
			}
		}
		sizeNganh = m_arr_Nganh.size();
	}
	public void filterLop (String khoaHoc, String nganh){
		if(m_arr_Lop!=null) m_arr_Lop.clear();
		m_arr_Lop = new ArrayList<String>();
		List<ClassLook> arr_All= new ArrayList<ClassLook>(m_arr_All.size());
		for (ClassLook clsLook: m_arr_All) {
			  arr_All.add((ClassLook)clsLook.clone());
			}
    
	    for (int i=0;i<arr_All.size();i++){
			if(arr_All.get(i).getKhoaHoc().equals(khoaHoc) && arr_All.get(i).getNganh().equals(nganh) && (!arr_All.get(i).getCheck()) ){
				m_arr_Lop.add(arr_All.get(i).getTenLop());
				for(int j=i+1;j<arr_All.size();j++)
					if (arr_All.get(j).getTenLop().equals(arr_All.get(i).getTenLop()))
						arr_All.get(j).setCheck(true);
			}
		}
		sizeLop = m_arr_Lop.size();
	}
}